using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using QLNS.Data;
using QLNS.Object;
using System.Windows.Forms;

namespace QLNS.Control
{
    class PhuCapCtrl
    {
        PhuCapData data = new PhuCapData();

        BindingSource bs = new BindingSource();
        public void HienthiPhuCapDataGridview(DataGridView dg, BindingNavigator bn)
        {
            BindingSource bs = new BindingSource();
            DataTable tbl = data.DanhSachPhuCap();
            bs.DataSource = tbl;
            bn.BindingSource = bs;
            dg.DataSource = bs;

        }
        public void HienthiPhuCapDataGridview(System.Windows.Forms.DataGridView dg, System.Windows.Forms.BindingNavigator bn,
            DateTimePicker dtpThang,ComboBox cmbMaNhanVien, TextBox txtTen, TextBox txtPhuCap)
        {
            System.Windows.Forms.BindingSource bs = new System.Windows.Forms.BindingSource();
            bs.DataSource = data.DanhSachPhuCap();

            dtpThang.DataBindings.Clear();
            dtpThang.DataBindings.Add("Value", bs, "Thang");

            cmbMaNhanVien.DataBindings.Clear();
            cmbMaNhanVien.DataBindings.Add("SelectedValue", bs, "ID");

            txtTen.DataBindings.Clear();
            txtTen.DataBindings.Add("Text", bs, "Ten");           

            txtPhuCap.DataBindings.Clear();
            txtPhuCap.DataBindings.Add("Text", bs, "PhuCap");

            bn.BindingSource = bs;
            dg.DataSource = bs;
        }
        public IList<PhuCapInfo> LayDanhSachPhuCap()
        {
            DataTable tbl = data.DanhSachPhuCap();
            IList<PhuCapInfo> ds = new List<PhuCapInfo>();

            foreach (DataRow row in tbl.Rows)
            {
                PhuCapInfo phucap = new PhuCapInfo();
                phucap.Thang = Convert.ToDateTime(row["Thang"]);
                phucap.ID = Convert.ToString(row["ID"]);
                phucap.Ten = Convert.ToString(row["Ten"]);                
                phucap.PhuCap = Convert.ToDouble(row["PhuCap"]);
                ds.Add(phucap);
            }
            return ds;
        }
        public string TimMa(String ma)
        {
            data.TimMa(ma);
            if (data != null)
                return ma;
            return null;
        }

        public string TimTen(string ten)
        {
            data.TimTen(ten);
            if (data != null)
                return ten;
            return null;
        }

        public DataRow NewRow()
        {
            return data.NewRow();
        }
        public void Add(DataRow row)
        {
            data.Add(row);
        }
        public bool Save()
        {
            return data.Save();
        }
        public void Update()
        {
            bs.MoveNext();
            data.Save();
        }
    }
}
